package com.zhixiang.core.util;
import org.activiti.engine.ProcessEngineConfiguration;  
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;  
import org.activiti.spring.SpringExpressionManager;  
import org.springframework.beans.BeansException;  
import org.springframework.beans.factory.FactoryBean;  
import org.springframework.context.ApplicationContext;  
import org.springframework.context.ApplicationContextAware;  
/**
 * @see http://blog.csdn.net/ie8848520/article/details/8634479
 * @category Spring2.5整合Activiti 5.11 解决MalformedParameterizedTypeException问题
 * 通常用activiti-spring插件实现act23张表的映射，在Spring 3.X中没有问题。
 * 但在Spring2.5使用如下配置，则会引发 MalformedParameterizedTypeException。
 * 由于Spring2.5的FactoryBean(即上述的ProcessEngineFactoryBean)不支持泛型，Spring尝试获取该泛型类型时会产生该异常。
 * 以下的类避免使用ProcessEngineFactoryBean， 而通过使用processEngineConfiguration的工厂方法buildProcessEngine的方式获取processEngine流程引擎。
 * */
public class SpringExpressionManagerFactoryBean implements FactoryBean, ApplicationContextAware {  
      
    ApplicationContext applicationContext;  
    ProcessEngineConfiguration processEngineConfiguration;  
      
      
    @Override  
    public Object getObject() throws Exception {  
        return new SpringExpressionManager(applicationContext, ((ProcessEngineConfigurationImpl) processEngineConfiguration).getBeans());  
    }  
  
    @Override  
    public Class getObjectType() {  
        return SpringExpressionManager.class;  
    }  
  
    @Override  
    public boolean isSingleton() {  
        return true;  
    }  
  
    @Override  
    public void setApplicationContext(ApplicationContext applicationContext)  
            throws BeansException {  
        this.applicationContext = applicationContext;  
    }  
  
    public void setProcessEngineConfiguration(  
            ProcessEngineConfiguration processEngineConfiguration) {  
        this.processEngineConfiguration = processEngineConfiguration;  
    }  
      
}  